<?php
include dirname(__FILE__) . "/../config/functions.php";
include_once dirname(__FILE__) . "/header.php";
?>
<div id="page-wrapper">

    <div class="row">
        <div class="col-lg-12">
            <?php
            //get member data
            if (!isset($_GET['id'])):
                ?>
                <div class="alert alert-danger">
                    Member Not Found.
                </div>
                <?php
            else:
                $member = mysql_query("select * from user where id = " . $_GET['id']);
                $row = mysql_fetch_assoc($member);

                //get levels NO
                $levelsNo = mysql_query("SELECT value FROM `option` WHERE `key` = 'levels_number'");
                $levelsNo = mysql_fetch_assoc($levelsNo);

                $levels = 0;
                if (isset($levelsNo['value']))
                    $levels = $levelsNo['value'];

                if ($row):
                    ?>
                    <h1><?php echo $row['name']; ?></h1>
                    <table class="table table-striped">
                        <tr>
                            <td>Email</td>
                            <td><?php echo $row['email']; ?></td>
                        </tr>
                        <tr>
                            <td>Username</td>
                            <td><?php echo $row['username']; ?></td>
                        </tr>
                        <tr>
                            <td>Ad Title</td>
                            <td><?php echo $row['textAd']; ?></td>
                        </tr>
                        <tr>
                            <td>Url</td>
                            <td><?php echo $row['url']; ?></td>
                        </tr>
                        <tr>
                            <td>Status</td>
                            <td><?php if ($row['status']): ?>Active<?php else: ?>Pending<?php endif; ?></td>
                        </tr>
                        <tr>
                            <td>Referred by</td>
                            <td>
                                <?php
                                if ($row['parent_id']):
                                    $memberParent = mysql_query("select * from user where id = " . $row['parent_id']);
                                    $row2 = mysql_fetch_assoc($memberParent);
                                    echo $row2['name'];
                                else:
                                    ?>
                                    -
                                <?php endif; ?></td>
                        </tr>
                        <?php for ($index = 1; $index <= $levels; $index++): ?>
                            <tr>
                                <td>Level<?php echo $index; ?> Count</td>
                                <td>
                                    <?php
                                    $lCount = mysql_query("select count(*) as totCount from affiliate where level = $index and parent_id = " . $row['id']);
                                    $row3 = mysql_fetch_assoc($lCount);
                                    echo $row3['totCount'];
                                    ?>
                                </td>
                            </tr>
                        <?php endfor; ?>
                        <tr>
                            <td></td>
                            <td>
                                <a class="btn btn-primary" href="member-delete-confirm.php?id=<?php echo $row['id']; ?>">Delete</a>
                            </td>
                        </tr>

                    </table>

                <?php else: ?>
                    <div class="alert alert-danger">
                        Member Not Found.
                    </div>
                <?php endif; ?>
            <?php endif; ?>
        </div>
    </div><!-- /.row -->

</div><!-- /#page-wrapper -->

<?php include_once dirname(__FILE__) . "/footer.php"; ?>